home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / bpreal.exe / BPRTEST.C < prev   
C/C++ Source or Header  |  1993-04-19  |  1KB  |  41 lines

  1. /*                      BPRTEST                      */
  2. /* Demonstrates Borland Pascal Real-Type Conversions */
  3. /*                  by Richard Biffl                 */
  4.  
  5. #include <stdio.h>
  6. #include "bpreal.c"
  7.  
  8.  
  9. char *convmessages[] = {
  10.     "Ok ", "+Un", "-Un", "Ovr", "Inf", "NaN"
  11. };
  12.  
  13.  
  14. int main()
  15. /* write and read file of Borland Pascal reals, BPREALS.DAT */
  16. {
  17.     FILE *realfile;
  18.     int i;
  19.     double d;
  20.     real r;
  21.  
  22.     printf("\nPrompting for 6 values to write to BPREALS.DAT\n");
  23.     realfile = fopen("BPREALS.DAT", "w+b");
  24.     for (i = 1; i <= 6; i++) {
  25.         do {
  26.             fflush(stdin);
  27.             printf("Enter a floating-point value: ");
  28.         } while (scanf("%lf", &d) == 0);
  29.         printf("% 23.16lg      Conversion result: %s\n",
  30.                d, convmessages[double_to_real(d, &r)]);
  31.         fwrite(&r, sizeof(r), 1, realfile);
  32.     }
  33.     rewind(realfile);
  34.     printf("\nReading and converting real values in BPREALS.DAT\n");
  35.     while (fread (&r, sizeof(r), 1, realfile))
  36.         printf ("Real value (converted to double): %23.16lg\n",
  37.                 real_to_double(r));
  38.     fclose(realfile);
  39.     return 0;
  40. }
  41.